SQL WHERE Clause

از عبارت WHERE برای فیلتر کردن رکوردها استفاده می شود.در زیر منتخبی از جدول "مشتریان" در پایگاه داده نمونه Northwind آمده است:

 

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry


 
Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico


 
Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden

عبارت SQL زیر همه مشتریان کشور "مکزیک" را در جدول "مشتریان" انتخاب می کند:

    

SELECT * FROM Customers
    WHERE Country='Mexico'; 

 

مثال عددی:

    

SELECT * FROM Customers
    WHERE CustomerID=1; 

 

عملگرهای زیر را می توان در عبارت WHERE استفاده کرد:

OperatorDescription
=Equal
>Greater than
<Less than
>=Greater than or equal
<=Less than or equal
<>Not equal. Note: In some versions of SQL this operator may be written as !=
BETWEENBetween a certain range
LIKESearch for a pattern
INTo specify multiple possible values for a column